import socket
from django.conf import settings
from django.shortcuts import HttpResponse
sock = socket.socket()

def startSocket(request):
    # ip = settings.LOCALHOSTIP
    # port = settings.LOCALHOSTPORT
    # #print("settings: ", ip, port)
    # sock.bind((ip, port))
    sock.listen(10)
    conn, ip = sock.accept()
    while True:
        try:
            
            res = conn.recv(4) #1024
            print(res)
        except:
            #pass
            continue
        items = {'res' : '人民'}
    return HttpResponse(json.dumps(items,ensure_ascii=False)) #强烈建议HttpResponse